function [data,data_trans] = generate_data_rand_categ(N,J,supp_z,alpha,beta,fractions)

% draw data

x = rand(N,J);
z = supp_z(randi(length(supp_z),N,J));

epsilon = -evrnd(0,1,[N,J]);

num_open = discretesample(fractions,N)';

choice = zeros(N,1);

for i=1:N
    
    VU = alpha*x(i,:) + epsilon(i,:);
    U = alpha*x(i,:) + beta*z(i,:) + epsilon(i,:);
    
    [~,ind_VU] = sort(VU,'descend');
    
    ind_open = ind_VU(1:num_open(i));
    ind_closed = setdiff(1:J,ind_open);
    
    U_new = U;
    U_new(ind_closed) = -Inf;
    
    [~,ind_good] = max(U_new);
    
    choice(i) = ind_good;
           
              
end

data.x = x;
data.z = z;
data.epsilon = epsilon;
data.choice = choice;
data.num_open = num_open;

data = struct2dataset(data);

data_trans = transform_data_nonorm(data,J);

end

